#import "MessageViewController.h"
#import "ScreenAdapter.h"
#import "CellStyleMessage.h"
#import "SMViewController.h"
#import "PrincipalNoticeViewController.h"
#import "SchoolNoticeViewController.h"
#import "ClassNoticeListViewController.h"
#import "MessageTableViewCell.h"
#import "RequestServerAPI.h"
#import "MJRefresh.h"
#import "SDWebImageManager.h"
#import "ImageUtil.h"
#import "UserDao.h"
#import "JsonUtil.h"
#import "PopUIManager.h"
#import "NetWorkManager.h"

#define PADDING 40

@interface MessageViewController()

@end

@implementation MessageViewController

@synthesize tableview, msgTableView, msgCellHeight, cell_data_array,foot_cell_data_array;

- (UIStatusBarStyle) preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
    
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
}
-(void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
    if ([self.tableview respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.tableview setSeparatorInset:UIEdgeInsetsZero];
    }
    
    if ([self.tableview respondsToSelector:@selector(setLayoutMargins:)]) {
        [self.tableview setLayoutMargins:UIEdgeInsetsZero];
    }
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
    
    firstTimeRefresh = true;
    
    tableview.delegate = self;
    tableview.dataSource = self;
    tableview.tag = 1;
    
    msgTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, APP_SCREEN_WIDTH, APP_SCREEN_HEIGHT - 64-49) style:UITableViewStylePlain];
//    msgTableView.backgroundColor = DefaultViewBackgroundColor;
    msgTableView.backgroundColor= [UIColor whiteColor];
    [self.view addSubview:msgTableView];
    msgTableView.dataSource = self;
    msgTableView.delegate = self;
    msgTableView.tag = 2;
    msgTableView.tableFooterView = [[UIView alloc]init];
    
    UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
    leftButton.frame = CGRectMake(0.0, 0.0, 22.0, 18.0);
    [leftButton setImage:[UIImage imageNamed:@"nav_btn_left"] forState:UIControlStateNormal];
    [leftButton addTarget:self action:@selector(leftBarAction) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
    leftButtonItem.style = UIBarButtonItemStylePlain;
    self.navigationItem.leftBarButtonItem = leftButtonItem;
    
    NSArray *itemArray = [NSArray arrayWithObjects:@"通知",@"消息", nil];
    UISegmentedControl *segControl = [[UISegmentedControl alloc]initWithItems:itemArray];
    segControl.frame = CGRectMake(0, 0, 150, 25);
    //默认选中第一项
    segControl.selectedSegmentIndex = 0;
    [segControl addTarget:self action:@selector(segmentControlCallback:) forControlEvents:UIControlEventValueChanged];
    
    self.navigationItem.titleView = segControl;
    
    msgTableView.hidden = YES;
    
    _sectionArray = [NSMutableArray arrayWithCapacity:2];
    NSMutableArray *rowArray = [NSMutableArray arrayWithCapacity:2];
    
    NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"班级通知",@"title",@"发送通知给自己的班级",@"content",@"class_notice", @"icon", nil];
    [rowArray addObject:dict];
    
    dict = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"幼儿园通知",@"title",@"接收园长发给老师和家长的通知",@"content",@"school_notice", @"icon", nil];
    [rowArray addObject:dict];
    
    [_sectionArray addObject:rowArray];
    
    rowArray = [NSMutableArray arrayWithCapacity:1];
    
    dict = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"小喇叭",@"title",@"语言课程更新啦",@"content",@"trumpet", @"icon", nil];
    [rowArray addObject:dict];
    [_sectionArray addObject:rowArray];
    
    msgCellHeight = [NSMutableArray arrayWithCapacity:10];
    
    [self.tableview setBackgroundColor:DefaultViewBackgroundColor];
}

//======================MJ Refresh Code====================
- (void)setUpRefreshPlugin
{
    // 1.下拉刷新(进入刷新状态就会调用self的headerRereshing)
    [msgTableView addHeaderWithTarget:self action:@selector(headerRefresh)];
    //#warning 自动刷新(一进入程序就下拉刷新)
    [msgTableView headerBeginRefreshing];
    
    // 2.上拉加载更多(进入刷新状态就会调用self的footerRereshing)
    [msgTableView addFooterWithTarget:self action:@selector(footerRefresh)];
    
    //设置文字(也可以不设置,默认的文字在MJRefreshConst中修改)
    msgTableView.headerPullToRefreshText = @"下拉刷新";
    msgTableView.headerReleaseToRefreshText = @"松开刷新";
    msgTableView.headerRefreshingText = @"正在刷新...";
    
    msgTableView.footerPullToRefreshText = @"上拉加载";
    msgTableView.footerReleaseToRefreshText = @"松开加载";
    msgTableView.footerRefreshingText = @"正在加载...";
}

-(void)headerRefresh {
    
    [self apiGetReplyMessageRequestType:@"new" baseId:@"-1"];
}

-(void)footerRefresh{
    NSString *baseId = [NSString stringWithFormat:@"%@", ((NSDictionary *)cell_data_array.lastObject)[@"reply_id"]];
    [self apiGetReplyMessageRequestType:@"old" baseId:baseId];
}

-(void) stopHeaderRefresh{
    [msgTableView headerEndRefreshing];
}

-(void) stopFooterRefresh{
    [msgTableView footerEndRefreshing];
}

- (void) setDataForHeaderRefresh:(NSDictionary*)dict{
    NSLog(@"head  >>>>%@",dict);
    NSString *head_url = [dict objectForKey:@"avatar_header"];
    cell_data_array = [NSMutableArray arrayWithCapacity:10];
    
    NSArray *replys_array = [dict objectForKey:@"replys"];
    for (NSDictionary* reply_dict in replys_array) {

        NSMutableDictionary *temp_dict = [NSMutableDictionary dictionaryWithCapacity:15];
        
        NSString *content = [reply_dict objectForKey:@"content"];
        NSString *reply_id = [reply_dict objectForKey:@"id"];
        NSString *post_id = [reply_dict objectForKey:@"post_id"];
        NSString *rereply_id = [reply_dict objectForKey:@"rereply_id"];
        NSString *rereply_uid = [reply_dict objectForKey:@"rereply_uid"];
        NSString *srccontent = [reply_dict objectForKey:@"srccontent"];
        NSString *status = [reply_dict objectForKey:@"status"];
        NSString *time = [reply_dict objectForKey:@"time"];
        NSString *uid = [reply_dict objectForKey:@"uid"];
        NSString *utype = [reply_dict objectForKey:@"utype"];
        
        NSDictionary *user_dict = [reply_dict objectForKey:@"otherinfo"];
        NSString *avatar = [user_dict objectForKey:@"avatar"];
        NSString *name = [user_dict objectForKey:@"name"];
        NSString *phone = [user_dict objectForKey:@"phone"];
        NSString *icon_url;
        if ([avatar isEqual:[NSNull null]]) {
            icon_url = @"null";
        }else{
            icon_url =[head_url stringByAppendingString:avatar];
        }
        
        [temp_dict setObject:content forKey:@"content"];
        [temp_dict setObject:reply_id forKey:@"reply_id"];
        [temp_dict setObject:post_id forKey:@"post_id"];
        [temp_dict setObject:rereply_id forKey:@"rereply_id"];
        [temp_dict setObject:rereply_uid forKey:@"rereply_uid"];
        [temp_dict setObject:srccontent forKey:@"srccontent"];
        [temp_dict setObject:status forKey:@"status"];
        [temp_dict setObject:time forKey:@"time"];
        [temp_dict setObject:uid forKey:@"uid"];
        [temp_dict setObject:utype forKey:@"utype"];
        [temp_dict setObject:name forKey:@"name"];
        [temp_dict setObject:phone forKey:@"phone"];
        [temp_dict setObject:icon_url forKey:@"icon_url"];
        
        [cell_data_array addObject:temp_dict];
    }
    
    //计算cell的高度
    [self initMsgCellHeightArray:@"new"];
}

- (void) setDataForFooterRefresh:(NSDictionary*)dict{
    NSLog(@"foot  >>>>%@",dict);
    NSString *head_url = [dict objectForKey:@"avatar_header"];
    
    foot_cell_data_array = [NSMutableArray arrayWithCapacity:10];
    
    NSArray *replys_array = [dict objectForKey:@"replys"];
    for (NSDictionary* reply_dict in replys_array) {
        
        NSMutableDictionary *temp_dict = [NSMutableDictionary dictionaryWithCapacity:15];
        
        NSString *content = [reply_dict objectForKey:@"content"];
        NSString *reply_id = [reply_dict objectForKey:@"id"];
        NSString *post_id = [reply_dict objectForKey:@"post_id"];
        NSString *rereply_id = [reply_dict objectForKey:@"rereply_id"];
        NSString *rereply_uid = [reply_dict objectForKey:@"rereply_uid"];
        NSString *srccontent = [reply_dict objectForKey:@"srccontent"];
        NSString *status = [reply_dict objectForKey:@"status"];
        NSString *time = [reply_dict objectForKey:@"time"];
        NSString *uid = [reply_dict objectForKey:@"uid"];
        NSString *utype = [reply_dict objectForKey:@"utype"];
        
        NSDictionary *user_dict = [reply_dict objectForKey:@"otherinfo"];
        NSString *avatar = [user_dict objectForKey:@"avatar"];
        NSString *name = [user_dict objectForKey:@"name"];
        NSString *phone = [user_dict objectForKey:@"phone"];
        NSString *icon_url;
        if ([avatar isEqual:[NSNull null]]) {
            icon_url = @"null";
        }else{
            icon_url =[head_url stringByAppendingString:avatar];
        }
        
        [temp_dict setObject:content forKey:@"content"];
        [temp_dict setObject:reply_id forKey:@"reply_id"];
        [temp_dict setObject:post_id forKey:@"post_id"];
        [temp_dict setObject:rereply_id forKey:@"rereply_id"];
        [temp_dict setObject:rereply_uid forKey:@"rereply_uid"];
        [temp_dict setObject:srccontent forKey:@"srccontent"];
        [temp_dict setObject:status forKey:@"status"];
        [temp_dict setObject:time forKey:@"time"];
        [temp_dict setObject:uid forKey:@"uid"];
        [temp_dict setObject:utype forKey:@"utype"];
        [temp_dict setObject:name forKey:@"name"];
        [temp_dict setObject:phone forKey:@"phone"];
        [temp_dict setObject:icon_url forKey:@"icon_url"];
        
        [cell_data_array addObject:temp_dict];
        [foot_cell_data_array addObject:temp_dict];
    }
    
    //计算cell的高度
    [self initMsgCellHeightArray:@"old"];
}

-(void)initMsgCellHeightArray:(NSString *) mtype{
    NSArray *nib_arr = [[NSBundle mainBundle]loadNibNamed:@"MessageTableViewCell" owner:self options:nil];
    MessageTableViewCell *cell = (MessageTableViewCell *)[nib_arr objectAtIndex:0];
    cell.accessoryType = UITableViewCellAccessoryNone;
    
    //计算布局，尺寸，文字高度
    CGFloat minX = CGRectGetMinX(cell.nick_name_lable.frame);
    CGFloat contentW = [ScreenAdapter getInstanse].screenWidth - minX - 10;
    
    if ([mtype isEqualToString:@"new"]) {
        [msgCellHeight removeAllObjects];
        
        for (NSDictionary *temp_mydict in cell_data_array) {
            CGFloat maxY = CGRectGetMaxY(cell.nick_name_lable.frame) + 10;
        
            NSString *str = [@"回复: " stringByAppendingString:[temp_mydict objectForKey:@"content"]];
        
            NSString *src_str = [@"我的评论: " stringByAppendingString:[temp_mydict objectForKey:@"srccontent"]] ;
        
            CGSize textSize =  [self sizeWithString:str font:[UIFont systemFontOfSize:16] maxSize:CGSizeMake(contentW, MAXFLOAT)];
        
            maxY = maxY + textSize.height + PADDING/2+5;
        
            textSize =  [self sizeWithString:src_str font:[UIFont systemFontOfSize:15] maxSize:CGSizeMake(contentW-10, MAXFLOAT)];
        
            maxY = maxY + textSize.height + PADDING;
        
            [msgCellHeight addObject:[NSNumber numberWithFloat:maxY]];
        }
    }else if([mtype isEqualToString:@"old"]){
        for (NSDictionary *temp_mydict in foot_cell_data_array) {
            CGFloat maxY = CGRectGetMaxY(cell.nick_name_lable.frame) + 10;
            
            NSString *str = [@"回复: " stringByAppendingString:[temp_mydict objectForKey:@"content"]];
            
            NSString *src_str = [@"我的评论: " stringByAppendingString:[temp_mydict objectForKey:@"srccontent"]] ;
            
            CGSize textSize =  [self sizeWithString:str font:[UIFont systemFontOfSize:16] maxSize:CGSizeMake(contentW, MAXFLOAT)];
            
            maxY = maxY + textSize.height + PADDING/2+5;
            
            textSize =  [self sizeWithString:src_str font:[UIFont systemFontOfSize:15] maxSize:CGSizeMake(contentW-10, MAXFLOAT)];
            
            maxY = maxY + textSize.height + PADDING;
            
            [msgCellHeight addObject:[NSNumber numberWithFloat:maxY]];
        }
    }
    
    [msgTableView reloadData];
}

-(void)segmentControlCallback:(UISegmentedControl *)Seg{
    NSInteger index = Seg.selectedSegmentIndex;
    switch (index) {
        case 0:  //通知
            msgTableView.hidden = YES;
            break;
        case 1:  //消息
            msgTableView.hidden = NO;
            if (firstTimeRefresh == true) {
                [self setUpRefreshPlugin];
                firstTimeRefresh = false;
            }
            
            break;
        default:
            break;
    }
}

-(void)leftBarAction{
    [[SMViewController sharedSMViewController]showLeftView:YES];
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSInteger section = indexPath.section;
    NSInteger row = indexPath.row;
    
    if (tableView.tag == 1) {
        static NSString *CellIdentifier = @"CellStyleMessage";

        CellStyleMessage *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            NSArray *nibArr = [[NSBundle mainBundle]loadNibNamed:@"CellStyleMessage" owner:self options:nil];
            cell = (CellStyleMessage *)[nibArr objectAtIndex:0];
            cell.accessoryType = UITableViewCellAccessoryNone;

            NSDictionary *dict = [[_sectionArray objectAtIndex:section] objectAtIndex:row];
            cell.itemName.text = [dict objectForKey:@"title"];
            [cell.itemIcon setImage:[UIImage imageNamed:[dict objectForKey:@"icon"]]];
            cell.itemMsg.text = [dict objectForKey:@"content"];
            return cell;
        }
    }else if(tableView.tag == 2){
        static NSString *CellIdentifier = @"MessageTableViewCell";
        MessageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            NSArray *nib_arr = [[NSBundle mainBundle]loadNibNamed:@"MessageTableViewCell" owner:self options:nil];
            cell = (MessageTableViewCell *)[nib_arr objectAtIndex:0];
            cell.accessoryType = UITableViewCellAccessoryNone;
        }
        
        NSString *content = [@"回复我: " stringByAppendingString:[[cell_data_array objectAtIndex:indexPath.row] objectForKey:@"content"]];
        
        NSString *srccontent = [@"我的评论: " stringByAppendingString:[[cell_data_array objectAtIndex:indexPath.row] objectForKey:@"srccontent"]];

        //计算布局，尺寸，文字高度
        CGFloat maxY = CGRectGetMaxY(cell.nick_name_lable.frame) + 10;
        CGFloat minX = CGRectGetMinX(cell.nick_name_lable.frame)+4;
        CGFloat contentW = [ScreenAdapter getInstanse].screenWidth - minX - 10;
        
        UILabel *reply_lable = [[UILabel alloc]init];
        reply_lable.numberOfLines = 0;
        reply_lable.lineBreakMode = NSLineBreakByCharWrapping;
        CGSize textSize =  [self sizeWithString:content font:[UIFont systemFontOfSize:16] maxSize:CGSizeMake(contentW, MAXFLOAT)];
        reply_lable.font = [UIFont systemFontOfSize:16];
        reply_lable.frame = CGRectMake(minX, maxY, contentW, textSize.height);
        reply_lable.textColor = UIColorMake(77, 77, 77);
        
        maxY = CGRectGetMaxY(reply_lable.frame)+PADDING/2+5;
        
        textSize =  [self sizeWithString:srccontent font:[UIFont systemFontOfSize:15] maxSize:CGSizeMake(contentW-10, MAXFLOAT)];
        
        UILabel *comment_lable = [[UILabel alloc]init];
        comment_lable.font = [UIFont systemFontOfSize:15];
        comment_lable.numberOfLines = 0;
        comment_lable.lineBreakMode = NSLineBreakByCharWrapping;
        comment_lable.frame = CGRectMake(minX+5, maxY, contentW-10, textSize.height);
        
        
        UIImage *image=[[UIImage imageNamed:@"detail_quote_bg"] resizableImageWithCapInsets:UIEdgeInsetsMake(18, 40, 8, 8)];
        
        UIImageView *bubble_imageView = [[UIImageView alloc]initWithImage:image];
        debugLog(@"%@:%f",srccontent,textSize.height);
        bubble_imageView.frame = CGRectMake(minX - 3, maxY-20, contentW, textSize.height+PADDING);
        
        
        cell.nick_name_lable.text = [[cell_data_array objectAtIndex:indexPath.row] objectForKey:@"name"];
        cell.nick_name_lable.textColor = UIColorMake(84, 134, 189);
        
        NSString *ttemp = [[cell_data_array objectAtIndex:indexPath.row] objectForKey:@"icon_url"];
        if ([ttemp isEqualToString:@"null"]) {
            [cell.user_icon setImage:[UIImage imageNamed:@"default_circle_icon"]];
        }else{
            [[SDWebImageManager sharedManager] downloadImageWithURL:[NSURL URLWithString:ttemp] options:SDWebImageLowPriority progress:^(NSInteger receivedSize, NSInteger expectedSize) {
                
            } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
                image = [[ImageUtil getInstance] circleImage:image withParam:0];
                [cell.user_icon setImage:image];
            }];
        }

        reply_lable.text = content;
        comment_lable.text = srccontent;
        
        [cell addSubview:bubble_imageView];
        [cell addSubview:reply_lable];
        [cell addSubview:comment_lable];
        
        return cell;
    }
    return nil;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView.tag == 1) {
        //该方法响应列表中行的点击事件
        NSInteger section = indexPath.section;
        NSInteger row = indexPath.row;
        if (section == 0) {
            if (row == 0) {
                //班级通知
                ClassNoticeListViewController *cnvc = [[ClassNoticeListViewController alloc]init];
                cnvc.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:cnvc animated:YES];
            }else if(row == 1){
                //幼儿园通知
                SchoolNoticeViewController *snvc = [[SchoolNoticeViewController alloc]init];
                snvc.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:snvc animated:YES];
            }
        }else if (section == 1) {
            if (row == 0) {
                //小喇叭
            }
        }
    }else if (tableView.tag == 2){
        
    }

    [tableView deselectRowAtIndexPath:indexPath animated:true];
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    if (tableView.tag == 1) {
        return _sectionArray.count;
    }else if (tableView.tag == 2){
        return 1;
    }
    return 0;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (tableView.tag == 1) {
        return [[_sectionArray objectAtIndex:section] count];
    }else if (msgTableView.tag == 2){
        if (cell_data_array.count > 0) {
            msgTableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
        }else {
            msgTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        }
        return cell_data_array.count;
    }
    return 3;
}

//设置Cell行高
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView.tag == 1) {
        return 60;
    }else if(tableView.tag == 2){
        return [[msgCellHeight objectAtIndex:indexPath.row] floatValue];
    }
    return 10;
}

//设置头高
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return CGFLOAT_MIN;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/**
 *  计算文本的宽高
 *
 *  @param str     需要计算的文本
 *  @param font    文本显示的字体
 *  @param maxSize 文本显示的范围
 *
 *  @return 文本占用的真实宽高
 */
- (CGSize)sizeWithString:(NSString *)str font:(UIFont *)font maxSize:(CGSize)maxSize
{
    NSDictionary *dict = @{NSFontAttributeName : font};
    // 如果将来计算的文字的范围超出了指定的范围,返回的就是指定的范围
    // 如果将来计算的文字的范围小于指定的范围, 返回的就是真实的范围
    
    CGSize size =  [str boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:dict context:nil].size;

    return size;
}


- (void)apiGetReplyMessageRequestType:(NSString*)requestType baseId:(NSString*)baseId{
    
    NSString* uid = [NSString stringWithFormat:@"%ld",[[UserDao getInstance] getUserId]];
    NSString* utype = @"1";
    
    NSDictionary *temp_dict = @{@"uid":uid,
                                @"utype":utype,
                                @"token":[[UserDao getInstance]getAccessToken],
                                @"dir":requestType,
                                @"baseid":baseId};
    
    NSString *dataString = [JsonUtil convertDictionaryToJson:temp_dict];
    
    NSString *msg = @"USER_GET_REREPLYS";
    
    PopUIManager *popUIMgr = [PopUIManager getInstanse];
    [popUIMgr showWaitingUI:self.view];
    
    [[NetWorkManager getInstanse] requestURLAsynMessage:msg data:dataString FinishBlock:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        if ([requestType isEqualToString:@"new"]) {
            [self stopHeaderRefresh];
        }else if ([requestType isEqualToString:@"old"]){
            [self stopFooterRefresh];
        }
        if (connectionError) { //连接失败
            NSLog(@"Http Error: %@   %ld", connectionError.localizedDescription,(long)connectionError.code);
            NSString *error_content = [NSString stringWithFormat:@"连接错误:%ld",(long)connectionError.code];
            [popUIMgr popAlertView:nil title:@"提示" message:error_content cancelButtonTitle:@"确定"];
        }else{//连接成功，判断 是否有数据返回
            if (data) {
                NSDictionary *dict = [JsonUtil convertDataToDictionary:data];
                if ([[dict objectForKey:@"ret"] integerValue]== 1) {
                    switch ([[dict objectForKey:@"retCode"] integerValue]) {
                        case 10020:
                            [[PopUIManager getInstanse]popAlertView:self title:@"提示" message:@"还没有发现更多的消息回复" cancelButtonTitle:@"确定"];
                            break;
                        case 1:
                            if ([requestType isEqualToString:@"new"]) { //下拉 获取最新数据的回调
                                [self setDataForHeaderRefresh:dict];
                            }else if ([requestType isEqualToString:@"old"]){//上拉 加载更多旧数据的回调
                                [self setDataForFooterRefresh:dict];
                            }
                            break;
                        default:
                            break;
                    }
                    
                }else{
                    [popUIMgr popAlertView:nil title:@"提示" message:@"数据解析错误" cancelButtonTitle:@"确定"];
                }
            }else{
                [popUIMgr popAlertView:nil title:@"提示" message:@"服务器没有返回数据" cancelButtonTitle:@"确定"];
            }
        }
        [popUIMgr removeWaitingUI];
    }];
    return;
}

@end
